
#ifndef _BSP_POWERCTRL_H
#define _BSP_POWERCTRL_H

#ifdef __cplusplus
extern "C" {
#endif


#define BSP_POWERCTRL_POWEREN_PORT                     GPIOA
#define BSP_POWERCTRL_POWEREN_PIN                      GPIO_PIN_7
#define BSP_POWERCTRL_POWEREN_CLKENABLE()              __HAL_RCC_GPIOA_CLK_ENABLE()
#define BSP_POWERCTRL_POWEREN_FUN                      GPIO_AF_MODE_0
#define BSP_POWERCTRL_POWEREN_OUT(X)                   HAL_GPIO_WritePin(BSP_POWERCTRL_POWEREN_PORT,BSP_POWERCTRL_POWEREN_PIN,(X == 1) ? GPIO_PIN_SET : GPIO_PIN_RESET)

#define BSP_POWERCTRL_POWERON()                        BSP_POWERCTRL_POWEREN_OUT(1)
#define BSP_POWERCTRL_POWEROFF()                       BSP_POWERCTRL_POWEREN_OUT(0)

#define BSP_POWERCTRL_BATTER_VAL_PORT                   GPIOB
#define BSP_POWERCTRL_BATTER_VAL_PIN                    GPIO_PIN_10
#define BSP_POWERCTRL_BATTER_VAL_CLKENABLE()            __HAL_RCC_GPIOB_CLK_ENABLE()
#define BSP_POWERCTRL_BATTER_VAL_FUN                    GPIO_MODE_ANALOG      
#define BSP_POWERCTRL_BATTER_VAL_CH                     HAL_ADC_CHANNEL_17 

#define BSP_POWERCTRL_POWER_VAL_PORT                    GPIOB
#define BSP_POWERCTRL_POWER_VAL_PIN                     GPIO_PIN_11
#define BSP_POWERCTRL_POWER_VAL_CLKENABLE()             __HAL_RCC_GPIOB_CLK_ENABLE()
#define BSP_POWERCTRL_POWER_VAL_FUN                     GPIO_MODE_ANALOG      
#define BSP_POWERCTRL_POWER_VAL_CH                      HAL_ADC_CHANNEL_18 

#define BSP_POWERCTRL_SHORTDET_PORT                     GPIOD
#define BSP_POWERCTRL_SHORTDET_PIN                      GPIO_PIN_0
#define BSP_POWERCTRL_SHORTDET_CLKENABLE()              __HAL_RCC_GPIOD_CLK_ENABLE()
#define BSP_POWERCTRL_SHORTDET_FUN                      GPIO_AF_MODE_F

#define BSP_POWERCTRL_SHORTFLAG_PORT                     GPIOA
#define BSP_POWERCTRL_SHORTFLAG_PIN                      GPIO_PIN_0
#define BSP_POWERCTRL_SHORTFLAG_CLKENABLE()              __HAL_RCC_GPIOA_CLK_ENABLE()
#define BSP_POWERCTRL_SHORTFLAG_FUN                      GPIO_AF_MODE_8
                   
#define BSP_POWERCTRL_SYSPOWER_PORT                      GPIOA
#define BSP_POWERCTRL_SYSPOWER_PIN                       GPIO_PIN_6
#define BSP_POWERCTRL_SYSPOWER_CLKENABLE()               __HAL_RCC_GPIOA_CLK_ENABLE()
#define BSP_POWERCTRL_SYSPOWER_FUN                       GPIO_AF_MODE_0

#define BSP_POWERCTRL_SYSPOWERON()                       HAL_GPIO_WritePin(BSP_POWERCTRL_SYSPOWER_PORT,BSP_POWERCTRL_SYSPOWER_PIN,GPIO_PIN_SET)
#define BSP_POWERCTRL_SYSPOWEROFF()                      HAL_GPIO_WritePin(BSP_POWERCTRL_SYSPOWER_PORT,BSP_POWERCTRL_SYSPOWER_PIN,GPIO_PIN_RESET)

#define BSP_POWERCTRL_EXPOWER_PORT                          GPIOB
#define BSP_POWERCTRL_EXPOWER_PIN                           GPIO_PIN_0
#define BSP_POWERCTRL_EXPOWER_CLKENABLE()                   __HAL_RCC_GPIOB_CLK_ENABLE()
#define BSP_POWERCTRL_EXPOWER_FUN                           GPIO_AF_MODE_0
#define BSP_POWERCTRL_EXPOWER()                             ((HAL_GPIO_ReadPin(BSP_POWERCTRL_EXPOWER_PORT,BSP_POWERCTRL_EXPOWER_PIN)==GPIO_PIN_SET)?0:1)

#ifdef __cplusplus
}
#endif
void bsp_powerctrl_init(void);
uint16_t  bsp_powerctrl_getpowervalue(void);
uint16_t  bsp_powerctrl_getbattervalue(void);
void bsp_powerctrl_openvc(uint32_t flag);
void bsp_powerctrl_closevc(void);
#endif /* __ZB32L03x_STARTERKIT_H */


